<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>订单管理</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="../assets/css/bootstrap.min.css">
    <script src="../assets/js/jquery.min.js"></script>
    <script src="../assets/js/bootstrap.min.js"></script>
    <script type="text/javascript">
        function onupdate(id){
            console.log(id)
            // window.location.replace("updateOrder.php?id="+id);
            $.ajax({
                url:"http://localhost/phalapi/public/index.php?s=App.Order.updateOrderInfoByOid",
                type: "POST",
                contentType:"application/json;charset=utf-8",
                data:JSON.stringify({
                    "order_id" : id
                }),
                dataType: "JSON",
                success: function (result) {
                    alert('发货成功');
                    window.location.replace("showAllOrder.php");
                },
                error: function (msg) {
                    alert("错误信息：" + msg);
                }
            })

        }

        //删除按钮
        function ondelete(id){
            console.log(id)
            $.ajax({
                url:"http://localhost/phalapi/public/index.php?s=App.Order.DeleteOrderInfoByOid",
                type: "POST",
                contentType:"application/json;charset=utf-8",
                data:JSON.stringify({
                    "order_id" : id
                }),
                dataType: "JSON",
                success: function (result) {
                    alert('删除成功');
                    window.location.replace("showAllOrder.php");
                },
                error: function (msg) {
                    alert("错误信息：" + msg);
                }
            })
        }


        // var s = "<tr class='tr_head'><td>序号</td><td>总金额</td><td>订单状态</td><td>订单时间</td><td>用户编号</td><td>操作</td></tr>";
        function inits(){
            var s = "<tr class='tr_head'><td>序号</td><td>订单编号</td><td>总金额</td><td>订单状态</td><td>订单时间</td><td>用户编号</td><td>操作</td></tr>";
            return s
        }

        function adds(s,z,a,d,e,id,flag){
            // var cc = flagc(flag);

            if(flag=='1'){
                var cc='未发货';
                // var cc = 1;
                s += "<tr><td>"+(z)+"</td><td>"+(id)+"</td><td>"+a+"元</td><td>"+cc+"</td><td>"+d+"</td><td>"+e+"</td><td><button class='btn btn-primary' onclick='ondelete(&quot;"+ id + "&quot;)' style='margin-right: 10px'>删除</button><button class='btn btn-primary' onclick='onupdate(&quot;"+ id + "&quot;)'>发货</button></td></tr>";
            }else if(flag=='2'){
                var cc='已发货';
                // var cc = 2;
                s += "<tr><td>"+(z)+"</td><td>"+(id)+"</td><td>"+a+"元</td><td>"+cc+"</td><td>"+d+"</td><td>"+e+"</td><td><button class='btn btn-primary' onclick='ondelete(&quot;"+ id + "&quot;)' style='margin-right: 10px'>删除</button></td></tr>";
            }

            return s
        }


        //查询全部订单
        $(function () {
            $.ajax({
                url: "http://localhost:80/phalapi/public/index.php?s=App.Order.getOrderList",
                type: "GET",
                dataType: "JSON",
                success: function (result) {
                    var user_data = result.data.info;
                    var z = 1;
                    console.log("data:" + user_data[0]['id'])
                    var pri_url = "../assets/fmwimages/";
                    var s = inits();
                    for (var i = 0; i < user_data.length; i++) {
                        var id = user_data[i]['id'];
                        var a = user_data[i]['money'];
                        var c = user_data[i]['uaid'];
                        var d = user_data[i]['createtime'];
                        var e = user_data[i]['uid'];
                        var flag = user_data[i]['flag'];
                        console.log(flag)
                        // if (c=='1'){cc='未支付'}else if (c=='2'){cc='已支付,待发货'}else if (c=='3'){cc='已发货,待收货'}
                        // else if (c='4'){cc='已收货,未评价'}else {cc='完成订单'}

                        s = adds(s,z,a,d,e,id,flag);
                        z++;
                        // console.log('iid'+id);
                    }
                    $("#tb_list").html(s);
                },
                error: function (msg) {
                    alert("错误信息：" + msg);
                }
            })
        })

        //搜索
        function search(){
            var searchId = $("input[name='username']").val();
            var searchState = $("#select_list option:selected").val();
            console.log(searchState);
            var s = inits()
            // $.ajax({
            //     url: "http://localhost:80/phalapi/public/index.php?s=App.Order.getOrderList",
            //     type: "GET",
            //     dataType: "JSON",
            //     success: function (result) {
            //         var user_data = result.data.info;
            //         var z = 1;
            //         console.log("data:" + user_data[0]['id'])
            //         var pri_url = "../assets/fmwimages/";
            //
            //         for (var i = 0; i < user_data.length; i++) {
            //             var id = user_data[i]['id'];
            //             var a = user_data[i]['money'];
            //             var c = user_data[i]['uaid'];
            //             var d = user_data[i]['createtime'];
            //             var e = user_data[i]['uid'];
            //             var flag = user_data[i]['flag'];
            //             // if (c=='1'){cc='未支付'}else if (c=='2'){cc='已支付,待发货'}else if (c=='3'){cc='已发货,待收货'}
            //             // else if (c='4'){cc='已收货,未评价'}else {cc='完成订单'}
            //
            //             if(flag=='1'){cc='未发货'}else if(flag=='2'){cc='已发货'}
            //
            //             if(searchName==''){
            //                 if(cc==searchState && searchState!=0){
            //                     s = adds(s,z,a,d,e,id,flag);
            //                     z++;
            //                 }
            //             }else if(searchState==0){
            //                 if(e==searchName){
            //                     s = adds(s,z,a,d,e,id,flag);
            //                     z++;
            //                 }
            //             }else{
            //                 if(e==searchName & cc==searchState){
            //                     s = adds(s,z,a,d,e,id,flag);
            //                     z++;
            //                     console.log('and');
            //                 }else{
            //                     var s = inits();
            //                     console.log('none');
            //                 }
            //             }
            //         }//for-end
            //
            //         $("#tb_list").html(s);
            //     },
            //     error: function (msg) {
            //         alert("错误信息：" + msg);
            //     }
            // })


            function likeOrder(){
                //订单模糊
                $.ajax({
                    url: "http://localhost/phalapi/public/index.php?s=App.Order.LikeQueryByOrderId",
                    data:{
                      "like_orderId":searchId
                    },
                    type: "GET",
                    dataType: "JSON",
                    success: function (result) {
                        var user_data = result.data.info;
                        var z = 1;
                        // console.log("data:" + user_data[0]['id'])
                        var pri_url = "../assets/fmwimages/";

                        for (var i = 0; i < user_data.length; i++) {
                            var id = user_data[i]['id'];
                            var a = user_data[i]['money'];
                            var c = user_data[i]['uaid'];
                            var d = user_data[i]['createtime'];
                            var e = user_data[i]['uid'];
                            var flag = user_data[i]['flag'];
                            // if (c=='1'){cc='未支付'}else if (c=='2'){cc='已支付,待发货'}else if (c=='3'){cc='已发货,待收货'}
                            // else if (c='4'){cc='已收货,未评价'}else {cc='完成订单'}

                            // if(flag=='1'){cc='未发货'}else if(flag=='2'){cc='已发货'}
                            //
                            // if(searchName==''){
                            //     if(cc==searchState && searchState!=0){
                            //         s = adds(s,z,a,d,e,id,flag);
                            //         z++;
                            //     }
                            // }else if(searchState==0){
                            //     if(e==searchName){
                            //         s = adds(s,z,a,d,e,id,flag);
                            //         z++;
                            //     }
                            // }else{
                            //     if(e==searchName & cc==searchState){
                            //         s = adds(s,z,a,d,e,id,flag);
                            //         z++;
                            //         console.log('and');
                            //     }else{
                            //         var s = inits();
                            //         console.log('none');
                            //     }
                            // }


                            if(searchState != 0){
                                if(searchState==flag){
                                    s = adds(s,z,a,d,e,id,flag);
                                    z++;
                                }
                            }else{
                                s = adds(s,z,a,d,e,id,flag);
                                z++;
                            }

                            // s = adds(s,z,a,d,e,id,flag);
                            // z++;

                        }//for-end
                        $("#tb_list").html(s);
                    },
                    error: function (msg) {
                        alert("错误信息：" + msg);
                    }
                })
            }

            function orderState(){
                //订单状态
                $.ajax({
                    url: "http://localhost/phalapi/public/index.php?s=App.Order.GetByOrderFlag",
                    data:{
                        "orderFlag":searchState
                    },
                    type: "GET",
                    dataType: "JSON",
                    success: function (result) {
                        var user_data = result.data.info;
                        var z = 1;
                        // console.log("data:" + user_data[0]['id'])
                        var pri_url = "../assets/fmwimages/";

                        for (var i = 0; i < user_data.length; i++) {
                            var id = user_data[i]['id'];
                            var a = user_data[i]['money'];
                            var c = user_data[i]['uaid'];
                            var d = user_data[i]['createtime'];
                            var e = user_data[i]['uid'];
                            var flag = user_data[i]['flag'];

                            s = adds(s,z,a,d,e,id,flag);
                            z++;

                        }//for-end
                        $("#tb_list").html(s);
                    },
                    error: function (msg) {
                        alert("错误信息：" + msg);
                    }
                })
            }

            //判断
            if(searchId==''){
                if(searchState!=''){
                    orderState()
                }
            }else if(searchState==0){
                if(searchId!=''){
                    likeOrder()
                }
            }else{
                if(searchId!='' & searchState!=0){
                    likeOrder(searchState)
                }
            }


        }
    </script>
</head>
<body>
<div class="row" style="width:98%;margin-left: 1%;margin-top: 5px;">
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                订单管理
            </div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-xs-5 col-sm-5 col-md-5 col-lg-5">
                        <div class="form-group form-inline">
                            <span>订单编号</span>
                            <input type="text" name="username" class="form-control">
                        </div>
                    </div>
                    <div class="col-xs-5 col-sm-5 col-md-5 col-lg-5">
                        <div class="form-group form-inline">
                            <span>订单状态</span>
                            <select name="orderStatus" class="form-control" id="select_list">
                                <option value="0">----------</option>
<!--                                <option value="未支付">未支付</option>-->
<!--                                <option value="已支付,待发货">已支付,待发货</option>-->
<!--                                <option value="已发货,待收货">已发货,待收货</option>-->
<!--                                <option value="已收货,未评价">已收货,未评价</option>-->
<!--                                <option value="完成订单">完成订单</option>-->
                                <option value="1">未发货</option>
                                <option value="2">已发货</option>
                            </select>
                        </div>
                    </div>
                    <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
                        <button type="button" class="btn btn-primary" id="search" onclick="search()"><span class="glyphicon glyphicon-search"></span></button>
                    </div>
                </div>
                <div style="height: 400px;overflow: scroll;">
                    <table id="tb_list" class="table table-striped table-hover table-bordered table-condensed">
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<!--<script type="text/javascript">
    function ondelete(id){
        console.log(id)
        $.ajax({
            url:"",
            type: "",
            dataType: "JSON",
            success: function (result) {

            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
    }
    function onupdate(id){
        console.log(id)
        // window.location.replace("updateGoods.php?id="+id);
    }
    //查询全部订单
    $(function () {
        $.ajax({
            url: "http://localhost:80/phalapi/public/index.php?s=App.Order.getOrderList",
            type: "GET",
            dataType: "JSON",
            success: function (result) {
                var user_data = result.data.info;
                var z = 1;
                console.log("data:" + user_data[0]['id'])
                var pri_url = "../assets/fmwimages/";
                var s = "<tr class='tr_head'><td>序号</td><td>总金额</td><td>订单状态</td><td>订单时间</td><td>用户编号</td><td>操作</td></tr>";
                for (var i = 0; i < user_data.length; i++) {
                    var id = user_data[i]['id'];
                    var a = user_data[i]['money'];
                    var c = user_data[i]['uaid'];
                    var d = user_data[i]['createtime'];
                    var e = user_data[i]['uid'];
                    if (c=='1'){cc='未支付'}else if (c=='2'){cc='已支付,待发货'}else if (c=='3'){cc='已发货,待收货'}
                    else if (c='4'){cc='已收货,未评价'}else {cc='完成订单'}
                    s += "<tr>" +
                        "<td>"+(z++)+"</td>" +
                        "<td>"+a+"</td>" +
                        "<td>"+cc+"</td>" +
                        "<td>"+d+"</td>" +
                        "<td>"+e+"</td>" +
                        "<td>" +
                        "<button class='btn btn-primary' onclick='ondelete("+id+")' style='margin-right: 10px'>删除</button>" +
                        "<button class='btn btn-primary' onclick='onupdate("+id+")'>修改</button>" +
                        "</td>" +
                        "</tr>";
                }
                $("#tb_list").html(s);
            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
    })
</script>-->
</body>
</html>